﻿using StarForce;

namespace ETHotfix
{
    /// <summary>
    /// 热更新层游戏入口
    /// </summary>
    public class HotfixGameEntry
    {
        const string LOG_START = "HotfixGameEntry Start";
        const string LOG_Shutdown = "HotfixGameEntry Shutdown";

        static string[] m_UIGroup = { "Low","Normal","Dialog","Tip"};

        public static System.Collections.Generic.List<System.Type> HotfixTypes;

        /// <summary>
        /// 事件
        /// </summary>
        public static EventManager Event
        {
            get;
            private set;
        }


        public static void Start()
        {
            Log.Info(LOG_START);

            HotfixTypes = StarForce.GFGame.ILRuntime.GetHotfixTypes();
            ETHotfix.ProtobufHelper.Init();
            ETHotfix.Game.EventSystem.Add(HotfixTypes);
            
            

            int cnt = m_UIGroup.Length;
            for (int i=0;i<cnt;i++) 
            {
                GFGame.UI.AddUIGroup(m_UIGroup[i],i*50);
            }

            Event = new EventManager();
            
            string assetName = AssetUtility.GetUIFormAsset("TestHotUI");
            // Game.UI.OpenUIForm(assetName, "Low",Constant.AssetPriority.UIFormAsset,false);

            GFGame.UI.OpenUIFormAsync(TestHotUI.PrefabName.GetUIPath(), "Low",  true);
        }

        public static void Update()
        {
            try
            {
                ETHotfix.Game.EventSystem.Update();
            }
            catch (System.Exception e)
            {
                Log.Error(e);
            }
        }

        public static void LateUpdate() 
        {
            try
            {
                ETHotfix.Game.EventSystem.LateUpdate();
            }
            catch (System.Exception e)
            {
                Log.Error(e);
            }
        }

        public static void Shutdown()
        {
            Log.Info(LOG_Shutdown);
        }
    }
}